package com.eh.proxy.virtual.component;

import javax.swing.*;
import java.awt.*;

/**
 * Created by David on 2016/5/3.
 */
class ImageComponent extends JComponent {
    private Icon icon;

    public ImageComponent(Icon icon) {
        this.icon = icon;
    }

    public void setIcon(Icon icon) {
        this.icon = icon;
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        int w = icon.getIconWidth();
        int h = icon.getIconHeight();
        icon.paintIcon(this, g, (800 - w) / 2, (600 - h) / 2);
    }
}
